#include <bits/stdc++.h>
using namespace std;

int a[3000005], b[3000005];

int main()
{
   // freopen("colour.in", "r", stdin);
    //freopen("colour.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t, n, ans = 0, f;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {

        cin >> n;
        ans = 0;
        for (int j = 1; j <= n; j++)
        {
            cin >> a[j];
        }
        for (int j = 1; j <= n; j++)
        {
            for (int k = j + 1; k <= n; k++)
            {
                f = 0;
                if (a[k] == a[j])
                {
                    if (a[k] > 0 && a[j] > 0)
                    {
                        f = a[k];
                        a[k] = 0;
                    }
                }
            }
            ans += f;
        }
        cout << ans << "\n";
    }
    return 0;
}
